//go:build windows
// +build windows

// export GOARCH=386

// 乐玩插件
package lwsoft

import (
	ole "github.com/go-ole/go-ole"
	"github.com/go-ole/go-ole/oleutil"
)

// LwSoft 结构体
type LwSoft struct {
	lw       *ole.IDispatch
	IUnknown *ole.IUnknown
}

// CoInitialize sta线程模型（单线程）初始化
func CoInitialize() {
	ole.CoInitialize(0)
}

// CoInitializeEx mta线程模型（多线程）初始化，第二传入参数为并发标志，如果不同函数错误
func CoInitializeEx() {
	ole.CoInitializeEx(0, 0)
}

// CoUninitialize 释放组件
func CoUninitialize() {
	ole.CoUninitialize()
}

// New 返回 *LwSoft.LwSoft
func New() (lw *LwSoft, err error) {
	var com LwSoft
	//创建对象
	com.IUnknown, err = oleutil.CreateObject("lw.lwsoft3")
	if err != nil {
		return nil, err
	}
	// 查询接口
	com.lw, err = com.IUnknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		return nil, err
	}
	return &com, nil
}

// Release 释放
func (com *LwSoft) Release() {
	com.IUnknown.Release()
	com.lw.Release()

}
